<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>window close</title>
</head>
<body>
  <button id="close">关闭当前页面</button>
  <button id="openClose">打开并关闭</button>
  <script>
    
    var btn = document.querySelector('#close');
    btn.addEventListener('click', function() {
      window.close();
    })

    var curWin;

    var btn2 = document.querySelector('#openClose');
    btn2.addEventListener('click', function() {
      curWin = window.open('https://www.qidian.com/');

      setTimeout(function() {
        curWin.close()
      }, 1000)
    })
  </script>
</body>
</html>